package com.qf.ems.controller;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/createCode")
public class CreateCodeController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //生成验证码
        ValidateCode validateCode = new ValidateCode(200, 30, 4, 10);
        String codes = validateCode.getCode();
        // 放到session中
        HttpSession session = req.getSession();
        session.setAttribute("codes",codes);
        System.out.println("======="+codes);
        //返回给浏览器
        validateCode.write(resp.getOutputStream());

    }
}
